package cn.itcast.com.network.tcp.exer04;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);

        Socket socket = serverSocket.accept();

        //读取数据
        //创建输入输出流
        InputStream in = socket.getInputStream();

        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        char[] buf = new char[1024];
        int len;
        FileWriter fileWriter = new FileWriter("D:\\代码\\代码\\代码\\cn\\itcast\\com\\network\\tcp\\q.txt");
        //read会阻塞
        while ((len = br.read(buf)) != -1){
            fileWriter.write(buf,0,len);
            fileWriter.flush();
        }
        OutputStream out = socket.getOutputStream();
        out.write("文件上传完毕".getBytes());

        fileWriter.close();
        socket.close();
        serverSocket.close();
    }
}
